#include <game/tgraphic.h>
#include <core/config.h>
#include <game/tobject.h>

void TGraphic::paint(QPainter &painter){
    vector2d leftCorner =  _object->getSize() * (-0.5) + _object->getPosition();

    if(_useImages){
        QPointF pos(leftCorner.x(),leftCorner.y());
        painter.drawImage  ( pos,imagesMap[_object->getState()] );
    }else{
        painter.drawRect(
                leftCorner.x(),
                leftCorner.y(),
                _object->getSize().x(),
                _object->getSize().y()
        );
    }
}

void TGraphic::hide (QPainter &painter){
    painter.eraseRect  ( _object->getPosition().x(),_object->getPosition().y(),_object->getSize().x(),_object->getSize().y());
}

void TGraphic::bindImageWithState(int state, const char * imagePath){
    imagesMap[state].load(imagePath);
}
